<template>
  <div class="sidebar">
    <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
             text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
      <template v-for="item in items">
        <template v-if="item.subs">
          <el-submenu :index="item.index" :key="item.index">
            <template slot="title">
              <i :class="item.icon"></i>
              <span slot="title" class="li">{{ item.title }}</span>
            </template>
            <el-menu-item-group v-for="(subItem,i) in item.subs" :key="i">
              <el-menu-item :index="subItem.index" class="li">{{ subItem.title }}</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </template>
        <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <i :class="item.icon"></i><span slot="title" class="li">{{ item.title }}</span>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script>
  import bus from '../common/bus';
  export default {
    data() {
      return {
        collapse: false,
        items: [
          {
            icon: 'el-icon-setting',
            index: 'homePage',
            title: '首页'
          },
          {
            icon: 'el-icon-tickets',
            index: '1',
            title: '主数据',
            subs: [
              {
                index: 'hospital',
                title: '医院'
              },
              {
                index: 'hospitalDimension',
                title: '医院维度'
              },
              {
                index: 'doctor',
                title: '医生'
              },
              {
                index: 'doctorDimension',
                title: '医生维度'
              },
            ]
          },
          {
            icon: 'el-icon-tickets',
            index: '2',
            title: '项目数据',
            subs: [
              {
                index: 'rocheGroupTAE',
                title: '罗氏TAE',
              },
              {
                index: 'anaplerosis',
                title: '回补医院ID',
              },
            ]
          },
          {
            icon: 'el-icon-tickets',
            index: '3',
            title: 'NLP',
            subs: [
              {
                index: 'identityOfNamedEntity',
                title: '医生命名实体识别'
              },
            ]
          },
          {
            icon: 'el-icon-tickets',
            index: '4',
            title: '论文',
            subs: [
              {
                index: 'paper',
                title: '同步ID'
              },
            ]
          },
        ]
      }
    },
    computed: {
      onRoutes() {
        return this.$route.path.replace('/', '');
      }
    },
    created() {
      bus.$on('collapse', msg => {
        this.collapse = msg;
      })
    }
  }
</script>

<style scoped>
  .sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
  }
  .sidebar::-webkit-scrollbar {
    width: 0;
  }
  .sidebar-el-menu:not(.el-menu--collapse) {
    width: 200px;
  }
  .sidebar > ul {
    height: 100%;
  }
  .li{
    font-size: 17px;
    font-weight: bold;
  }
</style>
<style>
  .el-menu-item-group > .el-menu-item-group__title{
    padding: 0 ;
  }
</style>
